home *** CD-ROM | disk | FTP | other *** search
- Path: info-server.bbn.com!ahsiung
- From: ahsiung@bbn.com (Anita Hsiung)
- Newsgroups: comp.lang.c
- Subject: Re: Checking for Ilegal Input
- Date: 12 Mar 1996 16:41:14 GMT
- Organization: Bolt Beranek and Newman (BBN)
- Sender: ahsiung@bbn.com
- Message-ID: <4i49fa$819@info-server.bbn.com>
- References: <313855C7.5E86@aol.com>
- NNTP-Posting-Host: snap.bbn.com
-
- gregace@aol.com writes:
- >
- >I used the scanf("%d",&number) to read the input.
- >
- >I check the illegal input by
- >
- >while (number<0 or number>15)
- >{ Printf("Enter a again:");
- > scanf("%d",&number);
- >}
-
- Why not try:
-
- char *resp; /* do some memory allocation */
- while ( (resp < '0') || (resp > '15') ) {
- printf("Enter a again:");
- scanf("%s", &resp);
- }
-
- and then do whatever atoi's you want.
-
- -- Anita --
- --
- --------->> Anita Hsiung, Technical Consultant <<---------------
- | BBN Domain Corporation | Data Analysis Suite |
- | Cambridge, Massachusetts, USA | ahsiung@bbn.com |
- | "Software Smart, Process Perfect" | 617-873-2854/492-6854 FAX |
-